package practice;

import java.util.*;

public class CoolNumbers {
    private static final String ALPHABET = "АВЕКМНОРСТУХ";
    private static final int REGION_MIN = 1;
    private static final int REGION_MAX = 199;
    private static final int LIST_SIZE = 2000000;

    public static List<String> generateCoolNumbers() {
        HashSet<String> list = new HashSet<>(LIST_SIZE);

        do {
            int char1 = (int) (Math.random() * ALPHABET.length());
            int digit = (int) (Math.random() * 9) + 1;
            int char2 = (int) (Math.random() * ALPHABET.length());
            int char3 = (int) (Math.random() * ALPHABET.length());
            int region = (int) (Math.random() * (REGION_MAX - REGION_MIN + 1)) + REGION_MIN;

            String number = ALPHABET.charAt(char1) +
                    String.format("%d%d%d", digit, digit, digit) +
                    ALPHABET.charAt(char2) +
                    ALPHABET.charAt(char3) +
                    String.format("%02d", region);

            list.add(number);
        } while (list.size() < LIST_SIZE);

        return new ArrayList<>(list);
    }

    public static boolean bruteForceSearchInList(List<String> list, String number) {
        return list.contains(number);
    }

    public static boolean binarySearchInList(List<String> sortedList, String number) {
        return Collections.binarySearch(sortedList, number) >= 0;
    }

    public static boolean searchInHashSet(HashSet<String> hashSet, String number) {
        return hashSet.contains(number);
    }

    public static boolean searchInTreeSet(TreeSet<String> treeSet, String number) {
        return treeSet.contains(number);
    }

}
